// 用户管理相关的API接口
import request from '@/utils/request.ts'
import type {
  UserSearchParams,
  UserListResponse,
  UserFormData,
  CommonResponse,
  BatchDeleteParams,
  RoleListResponse
} from './types.ts'

// 用户管理API枚举
enum UserAPI {
  // 用户相关
  USER_LIST = '/system/user/list',
  USER_ADD = '/system/user/add',
  USER_UPDATE = '/system/user/update',
  USER_DELETE = '/system/user/delete',
  USER_BATCH_DELETE = '/system/user/batchDelete',
  USER_STATUS = '/system/user/status',

  // 角色相关
  ROLE_LIST = '/system/role/list'
}

/**
 * 获取用户列表
 * @param params 搜索参数
 */
export const getUserListAPI = (params: UserSearchParams): Promise<UserListResponse> => {
  return request.post(UserAPI.USER_LIST, params)
}

/**
 * 添加用户
 * @param data 用户数据
 */
export const addUserAPI = (data: UserFormData): Promise<CommonResponse> => {
  return request.post(UserAPI.USER_ADD, data)
}

/**
 * 更新用户
 * @param data 用户数据
 */
export const updateUserAPI = (data: UserFormData): Promise<CommonResponse> => {
  return request.put(UserAPI.USER_UPDATE, data)
}

/**
 * 删除用户
 * @param id 用户ID
 */
export const deleteUserAPI = (id: number): Promise<CommonResponse> => {
  return request.delete(`${UserAPI.USER_DELETE}/${id}`)
}

/**
 * 批量删除用户
 * @param data 用户ID数组
 */
export const batchDeleteUserAPI = (data: BatchDeleteParams): Promise<CommonResponse> => {
  return request.post(UserAPI.USER_BATCH_DELETE, data)
}

/**
 * 更新用户状态
 * @param id 用户ID
 * @param status 状态值
 */
export const updateUserStatusAPI = (id: number, status: number): Promise<CommonResponse> => {
  return request.put(UserAPI.USER_STATUS, { id, status })
}

/**
 * 获取角色列表
 */
export const getRoleListAPI = (): Promise<RoleListResponse> => {
  return request.get(UserAPI.ROLE_LIST)
}
